<template>
   <div class="app-container">
      <el-form ref="formRef" :model="form" :rules="rules" label-width="120px">
         <el-row :gutter="20">
            <el-col :span="18">
               <el-form-item label="网站名称" prop="name">
                  <el-input v-model="form.name" placeholder="请输入" />
               </el-form-item>
            </el-col>
            <el-col :span="4">
               <el-button type="primary" @click="submitForm('name')">提交修改</el-button>
            </el-col>
         </el-row>
         <el-row :gutter="20">
            <el-col :span="18">
               <el-form-item label="网站域名" prop="domain">
                  <el-input v-model="form.domain" placeholder="请输入" />
               </el-form-item>
            </el-col>
            <el-col :span="4">
               <el-button type="primary" @click="submitForm('domain')">提交修改</el-button>
            </el-col>
         </el-row>
         <el-row :gutter="20">
            <el-col :span="18">
               <el-form-item label="网站页头" prop="keywords">
                  <el-input v-model="form.keywords" placeholder="请输入" />
               </el-form-item>
            </el-col>
            <el-col :span="4">
               <el-button type="primary" @click="submitForm('keywords')">提交修改</el-button>
            </el-col>
         </el-row>
         <el-row :gutter="20">
            <el-col :span="18">
               <el-form-item label="网站描述" prop="description">
                  <el-input v-model="form.description" placeholder="请输入" />
               </el-form-item>
            </el-col>
            <el-col :span="4">
               <el-button type="primary" @click="submitForm('description')">提交修改</el-button>
            </el-col>
         </el-row>
         <el-row :gutter="20">
            <el-col :span="18">
               <el-form-item label="网站title" prop="title">
                  <el-input v-model="form.title" placeholder="请输入" />
               </el-form-item>
            </el-col>
            <el-col :span="4">
               <el-button type="primary" @click="submitForm('title')">提交修改</el-button>
            </el-col>
         </el-row>
         <el-row :gutter="20">
            <el-col :span="18">
               <el-form-item label="微信AppID" prop="AppID">
                  <el-input v-model="form.AppID" placeholder="请输入" />
               </el-form-item>
            </el-col>
            <el-col :span="4">
               <el-button type="primary" @click="submitForm('AppID')">提交修改</el-button>
            </el-col>
         </el-row>
         <el-row :gutter="20">
            <el-col :span="18">
               <el-form-item label="微信AppSecret" prop="AppSecret">
                  <el-input v-model="form.AppSecret" placeholder="请输入" />
               </el-form-item>
            </el-col>
            <el-col :span="4">
               <el-button type="primary" @click="submitForm('AppSecret')">提交修改</el-button>
            </el-col>
         </el-row>
         <el-row :gutter="20">
            <el-col :span="18">
               <el-form-item label="微信分享图片" prop="desc">
                  <el-input v-model="form.desc" placeholder="请输入" />
               </el-form-item>
            </el-col>
            <el-col :span="4">
               <el-button type="primary" @click="submitForm('desc')">提交修改</el-button>
            </el-col>
         </el-row>
         <el-row :gutter="20">
            <el-col :span="18">
               <el-form-item label="其他script" prop="other_script">
                  <el-input v-model="form.other_script" type="textarea" rows="3" placeholder="请输入" />
               </el-form-item>
            </el-col>
            <el-col :span="4">
               <el-button type="primary" @click="submitForm('other_script')">提交修改</el-button>
            </el-col>
         </el-row>
         <el-row :gutter="20">
            <el-col :span="18">
               <el-form-item label="底部公共部分" prop="foot">
                  <editor v-model="form.foot" :min-height="300" style="width: 100%;"/>
               </el-form-item>
            </el-col>
            <el-col :span="4">
               <el-button type="primary" @click="submitForm('foot')">提交修改</el-button>
            </el-col>
         </el-row>
      </el-form>
      <
   </div>
</template>

<script setup name="CommonPageList">
import { getPageList, setting, } from "@/api/dudu";

const { proxy } = getCurrentInstance();

const apiUrl = '/setting';

const loading = ref(false);


const data = reactive({
  form: {
    name: undefined, // 网站名称
    domain: undefined, // 网站域名
    keywords: undefined, // 网站页头
    description: undefined, // 网站描述
    title: undefined, // 网站title
    AppID: undefined, // 微信AppID
    AppSecret: undefined, // 微信AppSecret
    desc: undefined, // 微信分享图片
    other_script: undefined, // 其它script
    foot: undefined, // 底部公共部分
  },
  
  rules: {
    name: [{ required: true, message: "网站名称不能为空", trigger: "blur" }],
    title: [{ required: false, message: "网站title不能为空", trigger: "blur" }],
  },
});

const { form, rules } = toRefs(data);

/** 查询页面列表 */
function getList() {
  loading.value = true;
  getPageList(apiUrl).then(res => {
   console.log(res);
    let data = res.result || [];
    for (let item of data) {
      form.value[item.title] = item.value;
    }
    loading.value = false;
  });
}


/** 提交按钮 */
function submitForm(file) {
   setting(apiUrl, {
      title: file,
      value: form.value[file]
   }).then(response => {
      proxy.$modal.msgSuccess("修改成功");
      getList();
   });
  
}

getList();
</script>
